{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Extended Isolation Forest Example"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Goal** \n",
    "\n",
    "Show how to use IF/EIF algorithms from the `eif` library and verify if EIF indeed performs better.\n",
    "\n",
    "**Introduction** \n",
    "\n",
    "For this short exercise I use Forest Cover dataset downloaded from [here](http://odds.cs.stonybrook.edu/forestcovercovertype-dataset/). Below you can find a detailed description of the dataset, as given on the website. The dataset contains 286048 observations and 10 features. The observations are labeled, so we do know up front which ones are anomalous. \n",
    "\n",
    "Another aspect of the comparison can be speed, as the authors of the [paper](https://arxiv.org/abs/1811.02141) state that there is no (significant) decrease in speed in Extended Isolation Forest\n",
    "\n",
    "*Dataset Description*\n",
    "\n",
    "The original ForestCover/Covertype dataset from UCI machine learning repository is a multiclass classification dataset. It is used in predicting forest cover type from cartographic variables only (no remotely sensed data). This study area includes four wilderness areas located in the Roosevelt National Forest of northern Colorado. These areas represent forests with minimal human-caused disturbances, so that existing forest cover types are more a result of ecological processes rather than forest management practices. This dataset has 54 attributes (10 quantitative variables, 4 binary wilderness areas and 40 binary soil type variables). Here, outlier detection dataset is created using only 10 quantitative attributes. Instances from class 2 are considered as normal points and instances from class 4 are anomalies. The anomalies ratio is 0.9%. Instances from the other classes are omitted."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Importing Libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:38:17.722128Z",
     "start_time": "2019-03-09T22:38:16.958991Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import scipy.io\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn import metrics\n",
    "from scipy.stats import multivariate_normal\n",
    "\n",
    "from sklearn.ensemble import IsolationForest\n",
    "from sklearn.metrics.pairwise import euclidean_distances\n",
    "import eif as iso\n",
    "\n",
    "# default plot settings\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## UDF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:38:17.743836Z",
     "start_time": "2019-03-09T22:38:17.724608Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def pretty_cm(y_pred, y_truth, labels):\n",
    "    '''\n",
    "    'Pretty' implementation of a confusion matrix with some evaluation statistics.\n",
    "    \n",
    "    Input:\n",
    "    y_pred - object with class predictions from the model\n",
    "    y_truth - object with actual classes\n",
    "    labels - list containing label names\n",
    "    '''\n",
    "    \n",
    "    cm = metrics.confusion_matrix(y_truth, y_pred)\n",
    "    ax= plt.subplot()\n",
    "    sns.heatmap(cm, annot=True, fmt=\"d\", linewidths=.5, square = True, cmap = 'BuGn_r')\n",
    "    ax.set_xlabel('Predicted label')\n",
    "    ax.set_ylabel('Actual label')\n",
    "    ax.set_title('Confusion Matrix', size = 15) \n",
    "    ax.xaxis.set_ticklabels(labels)\n",
    "    ax.yaxis.set_ticklabels(labels)\n",
    "    \n",
    "    print('#######################')\n",
    "    print('Evaluation metrics ####')\n",
    "    print('#######################')\n",
    "    print('Accuracy: {:.4f}'.format(metrics.accuracy_score(y_truth, y_pred)))\n",
    "    print('Precision: {:.4f}'.format(metrics.precision_score(y_truth, y_pred)))\n",
    "    print('Recall: {:.4f}'.format(metrics.recall_score(y_truth, y_pred)))\n",
    "    print('F1: {:.4f}'.format(metrics.f1_score(y_truth, y_pred)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Loading Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:38:18.768118Z",
     "start_time": "2019-03-09T22:38:17.745629Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "mat = scipy.io.loadmat('cover.mat')\n",
    "X = pd.DataFrame(mat['X'])\n",
    "y = pd.Series([x[0] for x in mat['y']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:38:18.777171Z",
     "start_time": "2019-03-09T22:38:18.770081Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(286048, 10)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T23:24:59.959082Z",
     "start_time": "2019-03-09T23:24:59.844142Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "      <td>286048.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>2914.242610</td>\n",
       "      <td>151.917224</td>\n",
       "      <td>13.598309</td>\n",
       "      <td>278.255251</td>\n",
       "      <td>45.839107</td>\n",
       "      <td>2414.978643</td>\n",
       "      <td>213.983685</td>\n",
       "      <td>225.246605</td>\n",
       "      <td>142.680092</td>\n",
       "      <td>2155.583857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>197.987324</td>\n",
       "      <td>107.488551</td>\n",
       "      <td>7.138464</td>\n",
       "      <td>210.458091</td>\n",
       "      <td>57.504597</td>\n",
       "      <td>1618.090012</td>\n",
       "      <td>24.955931</td>\n",
       "      <td>18.551910</td>\n",
       "      <td>36.501454</td>\n",
       "      <td>1423.976520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1988.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-173.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>2788.000000</td>\n",
       "      <td>60.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>120.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>1123.000000</td>\n",
       "      <td>201.000000</td>\n",
       "      <td>215.000000</td>\n",
       "      <td>120.000000</td>\n",
       "      <td>1165.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2933.000000</td>\n",
       "      <td>126.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>240.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>2016.000000</td>\n",
       "      <td>219.000000</td>\n",
       "      <td>227.000000</td>\n",
       "      <td>142.000000</td>\n",
       "      <td>1832.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>3041.000000</td>\n",
       "      <td>241.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>390.000000</td>\n",
       "      <td>67.000000</td>\n",
       "      <td>3386.000000</td>\n",
       "      <td>232.000000</td>\n",
       "      <td>239.000000</td>\n",
       "      <td>167.000000</td>\n",
       "      <td>2647.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>3433.000000</td>\n",
       "      <td>360.000000</td>\n",
       "      <td>66.000000</td>\n",
       "      <td>1397.000000</td>\n",
       "      <td>601.000000</td>\n",
       "      <td>7117.000000</td>\n",
       "      <td>254.000000</td>\n",
       "      <td>254.000000</td>\n",
       "      <td>254.000000</td>\n",
       "      <td>7173.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   0              1              2              3  \\\n",
       "count  286048.000000  286048.000000  286048.000000  286048.000000   \n",
       "mean     2914.242610     151.917224      13.598309     278.255251   \n",
       "std       197.987324     107.488551       7.138464     210.458091   \n",
       "min      1988.000000       0.000000       0.000000       0.000000   \n",
       "25%      2788.000000      60.000000       8.000000     120.000000   \n",
       "50%      2933.000000     126.000000      13.000000     240.000000   \n",
       "75%      3041.000000     241.000000      18.000000     390.000000   \n",
       "max      3433.000000     360.000000      66.000000    1397.000000   \n",
       "\n",
       "                   4              5              6              7  \\\n",
       "count  286048.000000  286048.000000  286048.000000  286048.000000   \n",
       "mean       45.839107    2414.978643     213.983685     225.246605   \n",
       "std        57.504597    1618.090012      24.955931      18.551910   \n",
       "min      -173.000000       0.000000       0.000000       0.000000   \n",
       "25%         8.000000    1123.000000     201.000000     215.000000   \n",
       "50%        30.000000    2016.000000     219.000000     227.000000   \n",
       "75%        67.000000    3386.000000     232.000000     239.000000   \n",
       "max       601.000000    7117.000000     254.000000     254.000000   \n",
       "\n",
       "                   8              9  \n",
       "count  286048.000000  286048.000000  \n",
       "mean      142.680092    2155.583857  \n",
       "std        36.501454    1423.976520  \n",
       "min         0.000000       0.000000  \n",
       "25%       120.000000    1165.000000  \n",
       "50%       142.000000    1832.000000  \n",
       "75%       167.000000    2647.000000  \n",
       "max       254.000000    7173.000000  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Isolation Forest"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In all models I will try to use the same settings, meaning:\n",
    "* number of trees in the forest = 100\n",
    "* maximum number of samples to draw for estimating each tree = 256\n",
    "* I know up front that there is 0.9% anomalies in the dataset and I will use this percentage to select the highest anomaly scores"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Scikit-Learn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:38:32.613655Z",
     "start_time": "2019-03-09T22:38:18.781474Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# define % of anomalies\n",
    "anomalies_ratio = 0.009\n",
    "\n",
    "if_sk = IsolationForest(n_estimators = 100, \n",
    "                        max_samples = 256,\n",
    "                        contamination = anomalies_ratio, \n",
    "                        behaviour= \" new\", \n",
    "                        random_state = np.random.RandomState(42))\n",
    "if_sk.fit(X)\n",
    "y_pred = if_sk.predict(X)\n",
    "y_pred = [1 if x == -1 else 0 for x in y_pred]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:38:33.558311Z",
     "start_time": "2019-03-09T22:38:32.615961Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#######################\n",
      "Evaluation metrics ####\n",
      "#######################\n",
      "Accuracy: 0.9831\n",
      "Precision: 0.0924\n",
      "Recall: 0.0866\n",
      "F1: 0.0894\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAU8AAAEYCAYAAADcRnS9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XecFdX9//HXW4jSNDaagB379ytGMRqMsQIaFWwJpohK\nRI3GEjUh/oy9l5iYGAQDioqiiaLECIhgQb8WUBBQRDaKsIqggr0gu5/fHzOL13XL3dm+9/3kMY+9\n98y5M2d22c+eNmcUEZiZWc2s1dgFMDNrjhw8zcwycPA0M8vAwdPMLAMHTzOzDBw8zcwycPCsJ5KO\nkDRN0geSvpT0mqTLJG1cT+frI+lFSV9IqrP5Z5IukvReXR0vz/OFpIWV7C9K919Uw+PuXpPPSNon\nPc9ONTmPFQ4Hz3og6Xrgn8DrwC+BvsANwKHALfV02hHAB0A/YM86PO4/0mM2pC+ALSTtlpsoqTew\nWbq/pnYHLqxB/hdJvo//zXAuKwCtG7sALY2kQ4HfAkMiYnTOrickjSQJpPVhO2BkRDxRlweNiGKg\nuC6PmYdPSYLXIGBmTvogYBqwa32dWJKAdSLiI+DZ+jqPNX+ueda9s4AXywVOACKiJCImlr2XtLGk\nMZLel/SZpMcrqG0tknSdpLMkFUtaKWmcpPXT/fukzfRWwF/SpuZt6b6QdFq5432jGS5pfUn/kPR2\n2uRfLOmWyvKnaVtIekDSR5I+lvRvSVuXyxOSzpB0haR3JS2XdJOkdfL8Po4DfpIGs7Kg9pM0/Rsk\n7SlpQnoNn0qaLennOfuPA/6aU66Q9Hju9UnaS9IMklrt0eWb7ZKOllQqaf+c426efg8uy/OarAVx\n8KxDkr4D/ACYlOdHHiBpEp8D/JTk5/FY+UBEEjT2B4YCvwcOAa5I95U1LwGuT19fWoNi/wnYiyTo\n9wPOAyrtM02D31Rge+BE4DhgC5Ka9Yblsp8NbAL8ArgWOAk4I89y3Q90TssG8EO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rKoi0cPz16xLO8A0mvDzn70cD4kbQcMALqR1O3fBiZExPz6Omd9\n6tixEx07dgKgffv2bLnlVixfvgxJfPJp8gv3ySef0LFTkuexadM4dMAAJPG/O/fi448/4t13l/N6\n0X/ZtXdvWrduTevWrdlm2215evp0+h10EPfeM46rrrmWtdZKAlFZ4AS4e+ydHHDggbw8b14DX3nL\n886K5byzYjkAn3z+KfMXF9Ft4y7MX7xwTZ72bdqtqS2VBc6v078dL4764cFMnPlYswmcdaXJVr0a\nQL002yX9HhhH8lfteWBG+vpuScPq45wN6a233uLV+fP5n//dmd8N+wM3XHsdfffbl+uvvYbTzzwL\ngOXLl9G5S5c1n+ncuQvLly1nm+224+np0/n8889ZuXIlM55/nnfeeQeA4sWLmTxxIsccfRS/HjqU\nNxctAmDZsmVMe/RRjv7poAa/1pZus87d2WXrHXnu1VkAXHbc71g89jl+vt/hXHD7dWvyDezTn/mj\nHuM/l47hhOvP+dZxBu1zGHc/9mCDlbupiCjNe2tp6qvPcwjQOyKuiog70+0qYPd0X4UkDZU0U9LM\nkSNH1lPRauezTz/l7DNO59w/DKNDhw7cO24c5w4bxiPTHuPc3w/joj+en2SsoHYiiR/06cNeP9yb\nwT/7GcPOOZudd+5F69atAFi16ivWXmcd7v7nvzji6KO48PzkWNdeeSVnnn02rVq1arDrLATt27Tj\nvgtGcObwi9Y018+/7Ro2/fn3GTttPKcddtyavA88PYnth+zLwIt/xaWDvxk8u2zYif/ZfDsmz3yi\nIYvfJEQNtpamvoJnKbBJBeld030VioiREbFbROw2dOjQeipadl999RW/PfMMDj7kUA44sC8A/37w\nAfY/8EAA+vbvz7y5cwHo1LkLy9IaJcCyZe/QsVNHAE48+WTuHT+eEaNGEwSbbroZAJ27dOaAvslx\n9z/gQBa+tgCAl1+ex+/PPpuDDtifKZMf4fJLL2Hao482zEW3UK1btea+C0YydtoDjH960rf23zXt\nAY784cHfSp8+9zm22mQzNlpvgzVpP9n7EMb/3yRWl6yu1zI3RaUReW8tTX0FzzO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YZedVlczMMnCz3cwsAwdPM7MM\nHDzNzDJw8DQzy8DB08wsAwdPM7MMHDzNzDL4/7jHdMJeXW9tAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x102bfd080>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pretty_cm(y_pred, y, [0, 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:38:33.569305Z",
     "start_time": "2019-03-09T22:38:33.562501Z"
    }
   },
   "source": [
    "The Forest is able to correctly identify 8.7% of anomalies in the dataset."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### eif"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By setting `ExtensionLevel` to 0 I am estimating a regular Isolation Forest. A couple of words about this implementation. First of all, as of now there is no way of setting random state for the model, so running it multiple times might yield different results. Also the `eif` implementation does not have that many parameters to configure. \n",
    "\n",
    "Another thing is that the model predicts the anomaly scores, but does not automatically identify which observations are considered outliers. To identify the anomalies, I sort the anomaly scores and retrieve indices of 0.9% of observations with highest scores."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:50:16.648233Z",
     "start_time": "2019-03-09T22:39:06.992488Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "if_eif = iso.iForest(X.values, \n",
    "                     ntrees = 100, \n",
    "                     sample_size = 256, \n",
    "                     ExtensionLevel = 0)\n",
    "\n",
    "# calculate anomaly scores\n",
    "anomaly_scores = if_eif.compute_paths(X_in = X.values)\n",
    "# sort the scores\n",
    "anomaly_scores_sorted = np.argsort(anomaly_scores)\n",
    "# retrieve indices of anomalous observations\n",
    "indices_with_preds = anomaly_scores_sorted[-int(np.ceil(anomalies_ratio * X.shape[0])):]\n",
    "# create predictions \n",
    "y_pred = np.zeros_like(y)\n",
    "y_pred[indices_with_preds] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T22:50:17.069636Z",
     "start_time": "2019-03-09T22:50:16.650445Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#######################\n",
      "Evaluation metrics ####\n",
      "#######################\n",
      "Accuracy: 0.9826\n",
      "Precision: 0.0672\n",
      "Recall: 0.0630\n",
      "F1: 0.0650\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAU8AAAEYCAYAAADcRnS9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xm8l3P+//HHU5aQLVRUiMk+I0tlH2timGJiMt8ZMX6y\nztiGaYx9mWFCxoxp1GgqgxhrBpHKOqRIiZgORScpVJYQnfP6/XFdJ5+Os3zOdfbzed7drtv5fN7X\n+3O939dJr97b9f4oIjAzs5pZrbErYGbWHDl4mpll4OBpZpaBg6eZWQYOnmZmGTh4mpll4OBZTyQd\nI2mipKWSlkv6n6SrJW1ST+XtI+kVSV9JqrP1Z5Iul/RRXV0vz/JC0uxKzhel5y+v4XV71OQzkg5I\ny9m5JuVY4XDwrAeSbgD+DbwD/ALoBQwBjgKG11OxtwJLgcOAverwuv9Ir9mQvgK6SNojN1FSd2DL\n9HxN9QAuq0H+V0h+j29nKMsKwOqNXYGWRtJRwHnAyRExIufU05KGkQTS+rA9MCwinq7Li0ZEMVBc\nl9fMwzKS4NUfmJqT3h+YCOxeXwVLErBWRHwKvFhf5Vjz55Zn3TsXeKVc4AQgIkoi4rGy95I2kTRK\n0seSvpD0VAWtrbmSrpd0rqRiSUskjZG0YXr+gLSb3gr4c9rVHJmeC0lnlbveKt1wSRtK+oek99Mu\n/3uShleWP03rIulBSZ9K+kzSw5K+Vy5PSDpb0h8kfShpkaRbJK2V5+9xDHBcGszKgtpxafoqJO0l\naWx6D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y5add1UyM8vA3XYzswwcPM3MMnDwNDPLwMHTzCwDB08zswwc\nPM3MMnDwNDPL4P8DHBPzAgc54YcAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1024287f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pretty_cm(y_pred, y, [0, 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Extended Isolation Forest"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This part is very similar to the vanilla Isolation Forest case (`eif` implementation) with the difference being the `ExtensionLevel`. To work on fully extended level, I set the level to 9 (number of dimensions - 1)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T23:01:06.189830Z",
     "start_time": "2019-03-09T22:50:17.071966Z"
    }
   },
   "outputs": [],
   "source": [
    "eif = iso.iForest(X.values, \n",
    "                  ntrees = 100, \n",
    "                  sample_size = 256, \n",
    "                  ExtensionLevel = X.shape[1] - 1)\n",
    "\n",
    "anomaly_scores = eif.compute_paths(X_in = X.values)\n",
    "anomaly_scores_sorted = np.argsort(anomaly_scores)\n",
    "indices_with_preds = anomaly_scores_sorted[-int(np.ceil(anomalies_ratio * X.shape[0])):]\n",
    "y_pred = np.zeros_like(y)\n",
    "y_pred[indices_with_preds] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-09T23:01:06.647281Z",
     "start_time": "2019-03-09T23:01:06.192235Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#######################\n",
      "Evaluation metrics ####\n",
      "#######################\n",
      "Accuracy: 0.9814\n",
      "Precision: 0.0000\n",
      "Recall: 0.0000\n",
      "F1: 0.0000\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAU8AAAEYC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DmwNsR8WyavjvJ4stPSwJYl+SWw28Bb0XE\nbABJfweG5TnHvsCxABGxCvhIUqcqeQak27T08wYkwfQrwD0R8Ul6jkLu5d9B0qUkXQMbkNzOWunO\niKgAZkt6M/0OA4Adc/pDv5qe+40CzmWWmYNny/ZpRPTOTUgD5PLcJGBSRAypkq83DbcknoDLI+KG\nKuc4PcM5xgCHRsTLko4D+ufsq1pWpOf+ZUTkBlkkbVnH85rViS/bW79ngX6SvgEgaT1J2wCvAT0l\nbZ3mG1LN8Y8AJ6fHtpW0IfAxSauy0kTgf3L6UrtL6gw8ARwmqaOkr5B0EdTmK8A8SesAP6my70hJ\nbdI6bwW8np775DQ/kraRtH4B5zGrF7c8W7mIWJS24G6X1D5NPi8i3pA0DHhA0mLgKWCHPEWcBoxK\nVxRaBZwcEc9IejqdCvRQ2u+5LfBM2vJdBvw0IqZKugN4CXibpGuhNucDz6X5X2HtIP068DjQBfh5\nRKyQ9FeSvtCpSk6+CDi0sJ+OWXZeVcnMLANftpuZZeDgaWaWgYOnmVkGDp5mZhk4eJqZZeDgaWaW\ngYOnmVkG/x/b4ekwoIkDNwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x103537048>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pretty_cm(y_pred, y, [0, 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As can be seen in the results, the model fails to identify a single anomaly in the dataset. Unfortunately, I do not have any explanation for this and if anyone knows what the issue might be, please let me know."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Conclusions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Extended Isolation Forest algorithm certainly is interesting and worth further exploring. It easily overcomes the limitations of the original model on a set of artificial examples, however, there seems to be some kind of problem when implementing it on a real life dataset. What is more, the current eif implementation is nearly as fast as the sklearn one. On my Macbook Pro the sklearn IF took 14s to train, while the eif implementations took roughly 10 minutes.\n",
    "\n",
    "I really hope the algorithm will be further improved and will serve as a good tool for identifying anomalies."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
